#ifndef MODELITEM_H
#define MODELITEM_H

#include "itemmodel_global.h"

#include <QObject>
#include <QSharedData>
#include <QSharedDataPointer>
#include <QVariant>
#include <QMetaType>


class ITEMMODELSHARED_EXPORT ModelItem : public QObject
{
    Q_OBJECT

    class Data : public QSharedData
    {
    public:
        Data()
        {
            orderChildren = false;
        }

        Data(const Data& other) : QSharedData(other)
        {
            name = other.name;
            orderChildren = other.orderChildren;
        }

        QString name;
        bool orderChildren;
    };

    Q_PROPERTY(QString name READ name WRITE setName NOTIFY sigRefresh)


public:

    Q_INVOKABLE ModelItem(QObject *parent = 0);
    ModelItem(const ModelItem& other);


    virtual QString name() const;
    virtual void setName(const QString& name);

    virtual bool childrenOrdered() const;
    virtual void setChildrenOrdered(bool ordered);

    virtual int type() const;
    virtual QVariant sortData() const;

    void setParent(QObject *object);
    ModelItem* parentItem() const;

    const ModelItem* rootItem() const;

    QList<ModelItem*> childItems() const;


signals:

    void sigChanged();
    void sigRefresh();


protected slots:

    virtual void onRefresh();


private:

    void initialize();

    QExplicitlySharedDataPointer<Data> d;


};


Q_DECLARE_METATYPE(ModelItem)


#endif // MODELITEM_H

